unit constant;

interface
type
   RecordDrawRegisters = record
                     x1,y1,x2,y2: integer;
                     entity,txt: string[8];
                   end;
   RecordTextMBM = record
                     x,y: integer;
                     txt: string[50];
                   end;
   RecordRegistrs = record
                     x,y: integer;
                     value,OldValue: ^word;
                   end;
    RecordArrows = record
                     x,y: integer;
                   end;
    TState = (State_Default, State_Demo, State_Step, State_Automat);
const
    CEsc   = #27;
    CExit  = ^X;
    CTab   = #9;
    CPlus  = #43;
    CMinus = #45;
    CNewValue = #62;
    CF9 = #67;
    CF7 = #65;
    CCtrlF9 = #102;
    dy      = 10;
    LimitDrawRegisters = 27;
    LimitTextMBM = 34;
    LimitTextRegistrs = 13;
    LimitDrawMemory = 13;
    LimitRegistrs =18;
    ElemeNumberOfTactLine = 12;
    LimitMemory = 28;
    LimitArrows=8;

    selectedItemIdx: integer = 1;
    
    speedValue: word = 1;
    stepValue : word=1;
    State: TState = State_Default;
    OldState: TState = State_Demo;
    RgA: word=0;
    RgD: word=0;
    NumberOfTact:  word=0;
    AKK: word=0;
    SchK: word=12;
    RgK: word=0;
    ADR: word=0;
    KOP: word=0;
    Aisp: word=0;
    ZF: word=0;
    CF: word=0;
    Loan: longint=0;

    DrawMemory: array[1..LimitDrawMemory] of RecordDrawRegisters =
    (
      (x1:180;y1:60;x2:260;y2:120;entity:'square'       ),      {CHK}
      (x1:500 ;y1:50  ;x2:580 ;y2:80;entity:'square'    ),      { $00C>FncAdr}
      (x1:500 ;y1:80  ;x2:580 ;y2:110;entity:'square'   ),      { $001>1 }
      (x1:500 ;y1:110  ;x2:580 ;y2:140;entity:'square'  ),      { $002>0}
      (x1:500  ;y1:140  ;x2:580 ;y2:170 ;entity:'square'),      { $003>5 }

      (x1:500 ;y1:170 ;x2:580 ;y2:200;entity:'square'   ),      { $004>4 }
      (x1:500 ;y1:200 ;x2:580;y2:230;entity:'square'    ),      {A}
      (x1:500 ;y1:230 ;x2:580 ;y2:260 ;entity:'square'  ),      { $106>6 }
      (x1:500 ;y1:260 ;x2:580;y2:290;entity:'square'    ),      {B}
      (x1:500 ;y1:290 ;x2:580;y2:320;entity:'square'    ),      {F}
      (x1:500 ;y1:320 ;x2:580 ;y2:350;entity:'square'   ),      { $600>End FncAdr}   
      (x1:130 ;y1:420 ;x2:210; y2:460;entity:'square'),         {STEP}
		   (x1:20;y1:420; x2:100; y2:460;entity:'square'));         {SPED}

  DrawRegisters: array[1..LimitDrawRegisters] of RecordDrawRegisters = 
  (
		(x1:20;y1:30;x2:300;y2:390;entity:'square'),                {PROCESSOR}
		(x1:340;y1:30;x2:620;y2:390;entity:'square'),               {RAM}
		(x1:40;y1:60;x2:120;y2:120;entity:'square'),                {RGF}
		(x1:40;y1:245;x2:120;y2:305;entity:'square'),               {AKK}
		(x1:140;y1:240;x2:280;y2:310;entity:'square'),              {RGK}
		(x1:380;y1:60;x2:460;y2:120;entity:'square'),               {RGA}
		(x1:380;y1:240;x2:460;y2:300;entity:'square'),              {RGD}

		(x1:140;y1:275;x2:280;y2:275;entity:'straight'),
		(x1:210;y1:275;x2:210;y2:310;entity:'straight'),
		(x1:85;y1:243;x2:85;y2:220;entity:'straight'  ),
		(x1:85;y1:220;x2:30;y2:220;entity:'straight'  ),
		(x1:85;y1:330;x2:85;y2:307;entity:'straight'  ),
		(x1:30;y1:220;x2:30;y2:330;entity:'straight'  ),
		(x1:30;y1:330;x2:290;y2:330;entity:'straight' ),
		(x1:210;y1:330;x2:210;y2:310;entity:'straight'),
		(x1:135;y1:330;x2:135;y2:220;entity:'straight'),
	  (x1:135;y1:220;x2:220;y2:220;entity:'straight'),
		(x1:220;y1:220;x2:220;y2:120;entity:'straight'),
		(x1:235;y1:240;x2:235;y2:120;entity:'straight'),
		(x1:290;y1:330;x2:290;y2:270;entity:'straight'),
		(x1:290;y1:270;x2:380;y2:270;entity:'straight'),
	  (x1:260;y1:90;x2:380;y2:90;entity:'straight'  ),
	  (x1:460;y1:90;x2:500;y2:90;entity:'straight'  ),
		(x1:460;y1:270;x2:500;y2:270;entity:'straight'),
	  (x1:235;y1:215;x2:290;y2:215;entity:'straight'),
		(x1:290;y1:215;x2:290;y2:90;entity:'straight' ),
	 	(x1:300;y1:120;x2:340;y2:120;entity:'straight')
	);
  Arrows:array [0..LimitArrows] of RecordArrows=
 (
    ( x :52   ; y:218 ),
    ( x :465  ; y:268  ),
    ( x :180  ; y:218  ),
    ( x :335  ; y:268  ),
    ( x :320  ; y:88   ),
    ( x :478  ; y:88  ),
    ( x :495  ; y:268  ),
    ( x :260  ; y:213  ),
    ( x :320  ; y:118  )
  );

    Memory: array[0..LimitMemory] of word =
   (
      $000C, {FncAdr}
      $0001, {One}
      $0000, {Zero}
      $0005, {5}
      $0004, {4}
      $0001, {A}
      $0006, {6}
      $0002, {B}
      $0000, {F}
      $0000, {G}
      $0013, {0208}
      $001C, {ExitAdr}
      {Fnc}
      $0205, {Loa A}
      $0003, {Add 5 }
      $0308, {Sto F}
      $0207, {Loa B}
      $0106, {Sub 6}
      $0309, {Sto G}
      $0418, {Jzinczero}
      $0208, {Loa F}
      $0109, {Sub G}
      $0104, {Sub 4}
      $0308, {Sto F}
      $050B, {JmpExit Adr}
      {IncZero}
      $0202, {Loa Zero}
      $0001, {Add One}
      $0302, {Sto Zero}
      $050A, {Jmp $000A}
      {Exit}
      $0600  {End FncAdr}
      );

    TextMBM: array[1..LimitTextMBM] of RecordTextMBM = 
    (
      (x:585;y:60;txt:'FncAdr'),
      (x:585;y:90;txt:'one'),
      (x:585;y:120;txt:'Zero'),
      (x:585;y:150;txt:'5'),
      (x:585;y:180;txt:'4'),
      (x:585;y:210;txt:'A'),
      (x:585;y:240;txt:'6'),
      (x:585;y:270;txt:'B'),
      (x:585;y:300;txt:'F'),
      (x:585;y:330;txt:'End FncAdr'),
      (x:220;y:50;txt:'CHK'),
      (x:50;y:230;txt:'AKK'),
      (x:245;y:230;txt:'RGK'),
      (x:175;y:315;txt:'KOP'),
      (x:245;y:315;txt:'ADR'),
      (x:410;y:50;txt:'RGA'),
      (x:420;y:230;txt:'RGD'),
      (x:100;y:50;txt:'RGF'),
      (x:230;y:410;txt:'Alt-X - exit Tab - chose elemeNumberOfTact'),
      (x:230;y:420;txt:'+/- chenge variebles'),
      (x:230;y:430;txt:'Ctrl-F9 - AVTOMAT'),
      (x:230;y:440;txt:'F9 - DEMO'),
      (x:230;y:450;txt:'F7 - TACT'),
      (x:230;y:460;txt:'Esc - STOP program'),
      (x:230;y:400;txt:'F = (A+5)-(B-6)-4'),  
      (x:170;y:410;txt:'STEP'),
      (x:60;y:410;txt:'SPEED'),
      (x:160;y:20;txt:'CPU'),
      (x:480;y:20;txt:'RAM'),
      (x:50;y:50;txt:'ALU'),
      (x:280;y:40;txt:'YY'),
      (x:510;y:40;txt:'RAM cels'),
      (x:310;y:110;txt:'R/W'),
      (x:270;y:205;txt:'+')
    );
  Registrs: array[1 .. LimitRegistrs] of RecordRegistrs = 
  (
     (x:190;y:70;value:@SchK;OldValue:@SchK),             {CHK}
     (x:510;y:63;value:@Memory[0];OldValue:@Memory[0]),   {FNCAdr}
     (x:510;y:93;value:@Memory[2];OldValue:@Memory[2]),   {0ne}
     (x:510;y:123;value:@Memory[1];OldValue:@Memory[1]),  {Zero}
     (x:510;y:153;value:@Memory[3];OldValue:@Memory[3]),   {5}
     (x:510;y:183;value:@Memory[4];OldValue:@Memory[4]),   {4}
     (x:510;y:213;value:@Memory[5];OldValue:@Memory[5]),   {A}
     (x:510;y:243;value:@Memory[6];OldValue:@Memory[6]),   {6}
     (x:510;y:273;value:@Memory[7];OldValue:@Memory[7]),   {B}
     (x:510;y:303;value:@Memory[8];OldValue:@Memory[8]),   {F}
     (x:510;y:333;value:@Memory[11];OldValue:@Memory[11]), {End FNcAdr}
     (x: 50; y:250; value:@AKK; OldValue:@AKK),            {AKK}
     (x:144;y:244; value:@RgK; OldValue:@RgK),             {RGK}
     (x:144;y:279; value:@KOP; OldValue:@KOP),             {KOP}
     (x:214;y:279; value:@ADR; OldValue:@ADR),             {ADR}
     (x:390;y: 70; value:@RgA; OldValue:@RgA),             {RGA}
     (x:390;y:250; value:@RgD; OldValue:@RgD),             {RGD}
     (x:50;y:70)                                           {RGF}
   );
implementation

begin

end.